package Model;


import java.util.List;
import ws.SPWebService;
import ws.StringArray;
import ws.WebServiceBean;

public class RequesToService {
	public String[][] getRequestUserById(int id) {
		WebServiceBean ws=getWebService();
	    List<StringArray> strArray = ws.getUserByID(id);
	    String[][] result = parser.Utils.toArrays(strArray);
		/*
		String[][] result = new String[2][4];
		if (id == 11) {
			result[0][0] = "11";
			result[0][1] = "user";
			result[0][2] = "login";
			result[0][3] = "FistPlayer";
			result[1][0] = "11";
			result[1][1] = "user";
			result[1][2] = "info";
			result[1][3] = "1";
		}
		if (id == 22) {
			result[0][0] = "22";
			result[0][1] = "user";
			result[0][2] = "login";
			result[0][3] = "SecondPlayer";
			result[1][0] = "22";
			result[1][1] = "user";
			result[1][2] = "info";
			result[1][3] = "2";
		}
*/
		return result;
	}

	public String[][] getTeamRatingById(int id) {
		WebServiceBean ws=getWebService();
	    List<StringArray> strArray = ws.getRatingOfTeam(id);//TODO
	    String[][] result = parser.Utils.toArrays(strArray);
	    return result;
	}
	public String[][] getPlayerRatingById(int id) {
		WebServiceBean ws=getWebService();
	    List<StringArray> strArray = ws.getRatingOfPlayer(id);//TODO
	    String[][] result = parser.Utils.toArrays(strArray);
		/*
		String[][] result = new String[2][4];
		if (id == 11) {
			result[0][0] = "11";
			result[0][1] = "rating";
			result[0][2] = "victory";
			result[0][3] = "5";
			result[1][0] = "11";
			result[1][1] = "rating";
			result[1][2] = "lose_out";
			result[1][3] = "0";
		}
		if (id == 22) {
			result[0][0] = "22";
			result[0][1] = "rating";
			result[0][2] = "victory";
			result[0][3] = "2";
			result[1][0] = "22";
			result[1][1] = "rating";
			result[1][2] = "lose_out";
			result[1][3] = "0";
		}

		if (id == 111) {
			result[0][0] = "111";
			result[0][1] = "rating";
			result[0][2] = "victory";
			result[0][3] = "5";
			result[1][0] = "111";
			result[1][1] = "rating";
			result[1][2] = "lose_out";
			result[1][3] = "0";
		}
		if (id == 222) {
			result[0][0] = "222";
			result[0][1] = "rating";
			result[0][2] = "victory";
			result[0][3] = "2";
			result[1][0] = "222";
			result[1][1] = "rating";
			result[1][2] = "lose_out";
			result[1][3] = "0";
		}
		*/

		return result;
	}

	public String[][] getRequestAllPlayers() {
		WebServiceBean ws=getWebService();
	    List<StringArray> strArray = ws.getAllPlayers();
	    String[][] result = parser.Utils.toArrays(strArray);
		
	    /*
		String[][] result = new String[4 * 2][4];

		result[0][0] = "1";
		result[0][1] = "player";
		result[0][2] = "rating_id";
		result[0][3] = "111";
		result[1][0] = "1";
		result[1][1] = "player";
		result[1][2] = "owner";
		result[1][3] = "11";
		result[2][0] = "1";
		result[2][1] = "player";
		result[2][2] = "firstname";
		result[2][3] = "Optimus";
		result[3][0] = "1";
		result[3][1] = "player";
		result[3][2] = "lastname";
		result[3][3] = "Prime";

		result[4][0] = "2";
		result[4][1] = "player";
		result[4][2] = "rating_id";
		result[4][3] = "222";
		result[5][0] = "2";
		result[5][1] = "player";
		result[5][2] = "owner";
		result[5][3] = "22";
		result[6][0] = "2";
		result[6][1] = "player";
		result[6][2] = "firstname";
		result[6][3] = "Megatron";
		result[7][0] = "2";
		result[7][1] = "player";
		result[7][2] = "lastname";
		result[7][3] = "Megatronich";
*/
		return result;
	}

	public String[][] getRequestAllTeams() {
		WebServiceBean ws=getWebService();
	    List<StringArray> strArray = ws.getAllTeams();
	    String[][] result = parser.Utils.toArrays(strArray);
		/*
		String[][] result = new String[2 * 2][4];

		result[0][0] = "1";
		result[0][1] = "team";
		result[0][2] = "rating_id";
		result[0][3] = "111";
		result[1][0] = "1";
		result[1][1] = "team";
		result[1][2] = "name";
		result[1][3] = "FirstTeam";

		result[2][0] = "2";
		result[2][1] = "team";
		result[2][2] = "rating_id";
		result[2][3] = "222";
		result[3][0] = "2";
		result[3][1] = "team";
		result[3][2] = "name";
		result[3][3] = "SecondTeam";
*/
		return result;
	}

	public String[][] getRequestAuthorization(String login, String pass) {
		WebServiceBean ws=getWebService();
	    List<StringArray> strArray = ws.authorize(parser.Utils.toList(new String[]{login,pass}));
	    String[][] result = parser.Utils.toArrays(strArray);
		/*
		if (login.equals("optimus")) {
			result = new String[2][4];
			result[0][0] = "11";
			result[0][1] = "user";
			result[0][2] = "firstname";
			result[0][3] = "Optimus";
			result[1][0] = "11";
			result[1][1] = "user";
			result[1][2] = "lastname";
			result[1][3] = "Prime";
		}*/
		return result;
	}
	
	private WebServiceBean getWebService(){
		SPWebService sp = new SPWebService();
		WebServiceBean ws =  sp.getWebServiceBeanPort();
		return ws;
	}
}
